// 清除网格 一级 二级 三级
function clearFeatures(f1 = 1, f2 = 1, f3 = 1) {
  if (f1) {
    map.removeFeature('FeatureCollection');
  }
  if (f2) {
    map.removeFeature('Feature');
  }
  if (f3) {
    map.removeFeature('Terminal');
  }
}
var spaceName = getQueryString('name') || '';
var gridId = getQueryString('id') || sessionStorage.getItem('id') || '';

if (spaceName.includes('县') || spaceName.includes('市') || spaceName.includes('区')) {
  spaceName = '';
}
var userId = $db.get('userId');
var usercode = getQueryString('usercode') || '';
var useMask = getQueryString('mask') || $Config.useMask || '1'; // 以外区域遮掉
var boundaryData = '';
var currentGirdNo = '';
var currentSpaceId = '';
var map = '';

var showCustomMapInfoWindow = function (data) {
  var html = '';
  if (data.iframe) {
    app.openLayerWindow(data.iframe, true, data.size);
    // html = `
    //   <div class="ymySpIframe ${data.lxid}">
    //     <iframe scrolling="no" allowtransparency="true" frameborder="0" src="">
    //   </div>`;
    // map.showInfoWindow(html, [data.lng, data.lat])
    // setTimeout(() => {
    //   var dom = document.getElementsByClassName('ymySpIframe')[0];
    //   var p = dom.getBoundingClientRect();
    //   var iframe = $('.ymySpIframe iframe')[0];
    //   iframe.src = `${data.iframe}&x=${p.x}&y=${p.y}`;
    // }, 200);
  } else {
    html = `<div class="getMapPositionClass">
      <div class="title" title="${data.title}" onclick="window.parent.openGyWindow('${data.url}','50%', '952px')">${data.title}</div>
      <div class="poiSearch" onclick="doPoiSearch([${data.lng}, ${data.lat}])"></div>
      <div class="content">
        ${((content) => {
          var strHtml = '';
          content.forEach(obj => {
            strHtml += `${obj.key}: ${obj.value}<br />`;
          });
          return strHtml;
        })(data.content)}
      </div>
      <div class="rightImg" style="cursor: pointer;" onclick="window.parent.previewImg('${data.img}')"><img src="${data.img}"></div>
    </div>`;
    map.showInfoWindow(html, [data.lng, data.lat])
    map.setCenterAndZoom([data.lng, data.lat], 16)
  }
};

var doPoiSearch = function (position) {
  map.clearActivities(n => n.clz == 'poiPoint');
  app.getAndLoad('poi', `/api/yth/wgh/poi.jsp?lng=${position[0]}&lat=${position[1]}&spaceId=${currentSpaceId}`, (data) => {
    data && (data instanceof Array) && data.forEach(p => {
      map.addBreatheMarker(p.id, p.type, [p.lng, p.lat], [30, 30], [15, 30], true, function () {
        p.url && app.openLayerWindow(p.url, false);
      }, {
        lwType: 'activity',
        clz: 'poiPoint'
      });
    });
  });
}

window.app = new Vue({
  el: '#APP',
  mixins: [], 
  data: function () {
    return {
      $Config,
      modules,
      wgTree: [],
      currentSpaceName: '',
      usercode, // 用户权限 2镇级
      key: getQueryString('key') || $Config.defaultKey,
      showBack: history.length > 1,
      spaceId: $Config.DefaultSpaceId
    };
  },
  methods: {
    changeKey: function (key) {
      this.key = key;
      this.showGridDetail(false);
    },

    addOuterFeature: function (features) {
      // return;
      this.currentFeatures = features;
      if (useMask == '0') return;
      map.addOuterFeature(features);
    },
    handlerWgTreeClick: function (clickItem, index) {
      var vm = this;
      if (usercode && !index) {
        // 镇级直接过
        return;
      }
      if (index != vm.wgTree.length - 1) {
        clearFeatures();
        vm.wgTree = vm.wgTree.slice(0, index + 1);
        currentGirdNo = clickItem.id;
        if (index == 0) {
          vm.addFeatureV1();
          vm.currentSpaceName = clickItem.name;
          currentSpaceId = getSpaceId(clickItem.name);
          map.setCenterAndZoom($Config.CENTER, $Config.ZOOM);
          vm.showGridDetail();
        }
        if (index == 1) {
          let grid = boundaryData.features.find(feature => feature.id == clickItem.id);
          vm.currentSpaceName = clickItem.name;
          currentSpaceId = getSpaceId(clickItem.name);
          vm.addOuterFeature(grid.features);
          grid.features.forEach(fl2 => {
            vm.addFeatureV2(fl2);
          });
          map.setCenterAndZoom(clickItem.cp, $Config.ZOOM_2);
          vm.showGridDetail();
        }
        if (index == 2) {
          let grid = vm.wgTree[1].features.find(feature => feature.id == clickItem.id);
          vm.addOuterFeature(grid.features);
          grid.features.forEach(fl3 => {
            vm.addFeatureV3(fl3);
          });
          map.setCenterAndZoom(clickItem.cp, $Config.ZOOM_3);
          vm.showGridDetail();
        }
      } else {
        if (index == 0) {
          map.setCenterAndZoom($Config.CENTER, $Config.ZOOM);
        } else if (index == 1) {
          map.setCenterAndZoom(clickItem.cp, $Config.ZOOM_2);
        } else if (index == 2) {
          map.setCenterAndZoom(clickItem.cp, $Config.ZOOM_3);
        }
      }
    },
    addFeatureV1: function () {
      var vm = this;
      vm.addOuterFeature(boundaryData.features);
      boundaryData.features.forEach(feature => {
        map.add3DBoundaryByFeatureV2(feature, $Config.WGH_POLOGON_COLOR[0] || '#101e6d', 0.7, 7500, [3, 16],
          function () {
            // 网格块的点击事件
            map.setCenterAndZoom(feature.properties.cp, $Config.ZOOM_2);
            clearFeatures();
            // // 更新面包线
            vm.wgTree = vm.wgTree.slice(0, 1);
            vm.wgTree.push({
              name: feature.properties.name,
              type: 'Feature',
              id: feature.id,
              cp: feature.properties.cp
            });
            currentGirdNo = feature.id;
            vm.currentSpaceName = feature.properties.name;
            currentSpaceId = getSpaceId(feature.properties.name);
            if (feature.features.length) {
              vm.addOuterFeature(feature.features);
              feature.features.forEach(vm.addFeatureV2);
              vm.showGridDetail();
            } else {
              vm.addOuterFeature(feature);
              map.add3DBoundaryByFeatureV2(feature, $Config.WGH_POLOGON_COLOR[2] || '#1ac9ff', 0.35, 1600,
                [3, 20], () => {
                  vm.showGridDetail();
                }, 'Terminal');
            }
          }, 'FeatureCollection');
      });
    },
    // 创建二级网格
    addFeatureV2: function (fl2) {
      var vm = this;
      map.add3DBoundaryByFeatureV2(fl2, $Config.WGH_POLOGON_COLOR[1] || '#3831fa', 0.2, 1000, [3, 16], function () {
        currentGirdNo = fl2.id;
        vm.currentSpaceName = fl2.properties.name;
        // currentSpaceId = getSpaceId(fl2.properties.name);
        vm.wgTree = vm.wgTree.slice(0, 2);
        vm.wgTree.push({
          name: fl2.properties.name,
          type: 'Terminal',
          id: fl2.id,
          cp: fl2.properties.cp,
          features: fl2.features
        });
        if (fl2.features && fl2.features.length) {
          clearFeatures();
          vm.addOuterFeature(fl2.features);
          fl2.features.forEach(vm.addFeatureV3);
          map.setCenterAndZoom(fl2.properties.cp, $Config.ZOOM_3);
          vm.showGridDetail();
        } else {
          clearFeatures();
          vm.addOuterFeature(fl2);
          vm.addFeatureV3(fl2);
          map.setCenterAndZoom(fl2.properties.cp, $Config.ZOOM_3);
          vm.showGridDetail();
        }
      });
    },
    // 创建三级网格
    addFeatureV3: function (fl3) {
      var vm = this;
      map.add3DBoundaryByFeatureV2(fl3, $Config.WGH_POLOGON_COLOR[1] || '#3831fa', 0.3, 1000, [3, 16], function () {
        map.setCenterAndZoom(fl3.properties.cp, $Config.ZOOM_4);
        clearFeatures();
        vm.addOuterFeature(fl3);
        map.add3DBoundaryByFeatureV2(fl3, $Config.WGH_POLOGON_COLOR[1] || '#3831fa', 0.3, 300, [3, 18]);
        currentGirdNo = fl3.id;
        // currentSpaceId = getSpaceId(fl2.properties.name);
        vm.wgTree = vm.wgTree.slice(0, 3);
        vm.wgTree.push({
          name: fl3.properties.name,
          type: 'Terminal',
          id: fl3.id,
          cp: fl3.properties.cp,
          features: fl3.features
        });
        vm.showGridDetail();
      });
    },
    gotoSomeplaceByGridname: function (gridName) {
      var vm = this;
      if (!gridName) {
        vm.handlerWgTreeClick(vm.wgTree[0], 0);
        return;
      }
      clearFeatures();
      var grid = boundaryData.features.find(n => n.properties.name == gridName);
      currentGirdNo = grid.id;
      vm.currentSpaceName = gridName;
      currentSpaceId = getSpaceId(gridName);
      vm.addOuterFeature(grid.features);
      grid.features.forEach(fl2 => {
        vm.addFeatureV2(fl2);
      });
      vm.wgTree = vm.wgTree.slice(0, 1);
      vm.wgTree.push({
        name: grid.properties.name,
        type: 'Feature',
        id: grid.id,
        cp: grid.properties.cp,
        features: grid.features
      });
      map.setCenterAndZoom(grid.properties.cp, $Config.ZOOM_2);
    },
    gotoSomeplaceByGridid: function (gridId) {
      var vm = this;
      if (!gridId) {
        vm.handlerWgTreeClick(vm.wgTree[0], 0);
        return;
      }
      clearFeatures();
      // 遍历街道
      vm.wgTree = vm.wgTree.slice(0, 1);
      for (let fl1 of boundaryData.features) {
        if (gridId.startsWith(fl1.id.slice(0, -3))) {
          if (gridId == fl1.id) {
            // 为街道
            vm.wgTree.push({
              name: fl1.properties.name,
              type: 'Feature',
              id: fl1.id,
              cp: fl1.properties.cp,
              features: fl1.features
            });
            currentGirdNo = fl1.id;
            vm.currentSpaceName = fl1.properties.name;
            currentSpaceId = getSpaceId(fl1.properties.name);
            vm.addOuterFeature(fl1.features);
            fl1.features.forEach(fl2 => {vm.addFeatureV2(fl2)})
            map.setCenterAndZoom(fl1.properties.cp, $Config.ZOOM_2);
            return;
          } else if (fl1.features) {
            // 遍历村
            vm.wgTree.push({
              name: fl1.properties.name,
              type: 'Feature',
              id: fl1.id,
              cp: fl1.properties.cp,
              features: fl1.features
            });
            for (let fl2 of fl1.features) {
              if (gridId.startsWith(fl2.id)) {
                if (gridId == fl2.id) {
                  // 为村
                  vm.wgTree.push({
                    name: fl2.properties.name,
                    type: 'Feature',
                    id: fl2.id,
                    cp: fl2.properties.cp,
                    features: fl2.features
                  });
                  currentGirdNo = fl2.id;
                  vm.addOuterFeature(fl2.features);
                  fl2.features.forEach(fl3 => {vm.addFeatureV3(fl3)})
                  map.setCenterAndZoom(fl2.properties.cp, $Config.ZOOM_3);
                  return;
                } else if (fl2.features) {
                  vm.wgTree.push({
                    name: fl2.properties.name,
                    type: 'Feature',
                    id: fl2.id,
                    cp: fl2.properties.cp,
                    features: fl2.features
                  });
                  for (let fl3 of fl2.features) {
                    if (gridId == fl3.id) {
                      vm.wgTree.push({
                        name: fl3.properties.name,
                        type: 'Feature',
                        id: fl3.id,
                        cp: fl3.properties.cp
                      });
                      currentGirdNo = fl3.id;
                      vm.addOuterFeature(fl3);
                      map.add3DBoundaryByFeatureV2(fl3, $Config.WGH_POLOGON_COLOR[1] || '#3831fa', 0.3, 300, [3, 18]);
                      map.setCenterAndZoom(fl3.properties.cp, $Config.ZOOM_4);
                      return;
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    showGridDetail: function (tongzhi = true) {
      tongzhi && parent.window.handlerGridChanged && parent.window.handlerGridChanged(this.wgTree[this.wgTree.length - 1], this.wgTree.length);
      // modules[this.key].showGridDetail && modules[this.key].showGridDetail();
    },
    // 统一请求加载方法
    getAndLoad: function (chartName, apiUrl, callback, ...params) {
      var vm = this;
      var keys = Object.keys($APIDATA);
      var key = '';
      keys.forEach(k => {
        if (k.includes(apiUrl)) {
          key = k;
        }
      });
      if ($APIDATA[key]) {
        console.log('假数据请求:' + key);
        callback($APIDATA[key].data, params);
        return;
      }
      vm.loading = true;
      if (!(apiUrl.startsWith('/') || apiUrl.startsWith('http'))) {
        apiUrl = '/' + apiUrl;
      }

      function doSuccess(res) {
        vm.loading = false;
        if (!(res instanceof Object)) {
          res = JSON.parse(res);
        }
        if (res.data) {
          callback(res.data, params);
        } else {
          console.log(`获取数据失败[${chartName}]`);
        }
      }
      $.get(apiUrl, doSuccess);
    },
    
    clearActivities: function () {
      map.clearActivities();
    },
    pageFloat: function (offset, option) {
      var vm = this;
      !option && (option = vm.listObject);
      option.params.pageNo += offset;
      vm.doListSerch(option);
    },
    enterSearch: function () {
      this.listObject.params.pageNo = 1;
      this.doListSerch();
    },
    handlerStatusChange: function (item, option) {
      if (item.active) {
        return;
      }
      !option && (option = this.listObject);
      option.params.pageNo = 1;
      $Util.toggleAttr(option.filter, n => n.name == item.name);
      this.doListSerch(option);
    },
    showWgItemList(item) {
      var vm = this;
      if (item.click == 'wanggeyuan' || item.name == '网格人员') {
        this.listObject = {
          title: '网格人员',
          type: 'wgry',
          isFirstPage: true,
          isLastPage: true,
          params: {
            type: 'wgy',
            pageNo: 1,
            pageSize: 7,
            keyword: ''
          },
          listApi: '/api/yth/zhdd/queryPersonLoc.jsp',
          detailApi: '/api/v1/zhdd/getPersonInfo.jsp?id=',
          filter: JSON.parse(JSON.stringify(RY_FILTER)),
          // list: [{"lng":118.62625034865277,"name":"\u5f20\u5fc5\u521a","dist":"0.00km","id":"12abdc2j8s2b4","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"online"},{"lng":118.62625034865277,"name":"\u6731\u9601","dist":"0.00km","id":"12t5w8y2dtpo2","time":"2020-04-21 17:40:37","type":"grid","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u674e\u65ed\u6625","dist":"0.00km","id":"13qx9kq7xruxr","time":"2020-04-21 17:40:37","type":"grid","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u5218\u5b89","dist":"0.00km","id":"14fkepp3zwamo","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u5218\u8000","dist":"0.00km","id":"16aq452ryezsw","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u8d75\u5efa\u6d32","dist":"0.00km","id":"17pkp35sr81d7","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u7ef3\u524d\u6c11","dist":"0.00km","id":"1cfivntq8zrsv","time":"2020-04-21 17:40:37","type":"grid","lat":33.90588901866005,"shichang":"0min","status":"offline"}]
        }
        this.doListSerch();
      } else if (item.click == 'zhifayuan' || item.name == '执法队员') {
        this.listObject = {
          title: '执法队员',
          type: 'wgry',
          isFirstPage: true,
          isLastPage: true,
          params: {
            type: 'zfy',
            pageNo: 1,
            pageSize: 7,
            keyword: ''
          },
          listApi: '/api/yth/zhdd/queryPersonLoc.jsp',
          detailApi: '/api/v1/zhdd/getPersonInfo.jsp?id=',
          filter: JSON.parse(JSON.stringify(RY_FILTER)),
          // list: [{"lng":118.62625034865277,"name":"\u5f20\u5fc5\u521a","dist":"0.00km","id":"12abdc2j8s2b4","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"online"},{"lng":118.62625034865277,"name":"\u6731\u9601","dist":"0.00km","id":"12t5w8y2dtpo2","time":"2020-04-21 17:40:37","type":"grid","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u674e\u65ed\u6625","dist":"0.00km","id":"13qx9kq7xruxr","time":"2020-04-21 17:40:37","type":"grid","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u5218\u5b89","dist":"0.00km","id":"14fkepp3zwamo","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u5218\u8000","dist":"0.00km","id":"16aq452ryezsw","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u8d75\u5efa\u6d32","dist":"0.00km","id":"17pkp35sr81d7","time":"2020-04-21 17:40:37","type":"law","lat":33.90588901866005,"shichang":"0min","status":"offline"},{"lng":118.62625034865277,"name":"\u7ef3\u524d\u6c11","dist":"0.00km","id":"1cfivntq8zrsv","time":"2020-04-21 17:40:37","type":"grid","lat":33.90588901866005,"shichang":"0min","status":"offline"}]
        }
        this.doListSerch();
      } else if (item.click == 'shijian') {
        let filter = JSON.parse(JSON.stringify(SJ_FILTER));
        if (filter.map(n => n.name).includes(item.name)) {
          $Util.toggleAttr(filter, (n) => n.name == item.name);
        }
        this.listObject = {
          title: '事件上报',
          type: 'shijian',
          filter: filter,
          isFirstPage: true,
          isLastPage: true,
          params: {
            pageNo: 1,
            pageSize: 7,
            keyword: ''
          },
          listApi: '/api/yth/zhdd/queryEvents.jsp',
          detailApi: '/api/v3/zhdd/getEventInfo.jsp?id=',
          detailPage: (item) => {
            if (item.uid) {
              return `/general_10/zhzf/view/event/handlerView.jsp?fromDate=${item.fromDate}&roleTypeId=${item.roleTypeId}&id=${item.uid}`;
            } else {
              return '/general_10/zhzf/view/event/eventView.jsp?id=' + item.id;
            }
          }
        }
        this.doListSerch();
      } else if (item.click == 'huiban') {
        let filter = JSON.parse(JSON.stringify(SJ_FILTER2));
        this.listObject = {
          title: item.name,
          type: 'shijian',
          filter: filter,
          isFirstPage: true,
          isLastPage: true,
          params: {
            pageNo: 1,
            pageSize: 7,
            keyword: '',
            type: 'hb',
            status: filter[0].value
          },
          listApi: 'api/v3/zhdd/hb/hbQueryEvents.jsp',
          detailApi: 'api/v3/zhdd/getEventInfo.jsp?type=hb&id=',
          detailPage: '/datav/view/viewContent.jsp?entityName=ExtYthHbgz&id=',
        }
        this.doListSerch();
      } else if (item.click == 'jiankong') {
        // debugger
        // parent.openWindowLeft && parent.openWindowLeft('/datav/view/hikvision/iSecure/gy/jk-left.jsp?type=' + (item.name == '监控' ? '' : item.name));
        // parent.openWindowRight &&  parent.openWindowRight('/datav/view/hikvision/iSecure/gy/jk-right.jsp?type=' + (item.name == '监控' ? '' : item.name));
        if (item.name == '无人机') {
          this.listObject = {
            title: item.name,
            type: 'jiankong',
            isFirstPage: true,
            isLastPage: true,
            params: {
              pageNo: 1,
              pageSize: 7,
              keyword: ''
            },
            isWrj: true,
            list: [{
                name: '无人机001',
                high: '33m',
                speed: '12m/s',
                lat: '37.21321',
                lng: '123.32131',
                rotation: '53°',
                time: '15min36s'
              },
              {
                name: '无人机002',
                high: '33m',
                speed: '12m/s',
                lat: '37.21321',
                lng: '123.32131',
                rotation: '53°',
                time: '15min36s'
              },
              {
                name: '无人机003',
                high: '33m',
                speed: '12m/s',
                lat: '37.21321',
                lng: '123.32131',
                rotation: '53°',
                time: '15min36s'
              }
            ]
          }
        } else {
          this.listObject = {
            title: item.name,
            handlerItemClick: (item) => {
              vm.openLayerWindow(`/datav/view/hikvision/iSecure/gy/preview.jsp?id=${item.id}&spaceId=${currentSpaceId}`, false)
            },
            titleClick: () => {
              vm.openLayerWindow(`/datav/view/hikvision/iSecure/gy/previewWindows.jsp?type=${item.name}&spaceId=${currentSpaceId}`, false)
            },
            type: 'jiankong',
            icon: item.icon,
            filter: [],
            isFirstPage: true,
            isLastPage: true,
            params: {
              pageNo: 1,
              pageSize: 9,
              keyword: '',
              type: item.name
            },
            listApi: '/api/yth/zhdd/getCameras.jsp',
          }
          this.doListSerch();
        }
      }
    },
    openLayerWindow(url, showClose = true, size = [1800, 960]) {
      var isNy = location.href.includes('local');
      var x = (window.parent.innerWidth - size[0]) / 2;
      var y = (window.parent.innerHeight - size[1]) / 2;
      var poStr = (url.includes('?') ? '&x=' : '?x=') + x + '&y=' + y;
      parent.layer.open({
        closeBtn: isNy || showClose,
        type: 2,
        title: false,
        shadeClose: false,
        shade: 0,
        skin: 'layerSkin',
        area: [size[0] + 'px', size[1] + 'px'],
        content: [url + poStr, 'no']
      });
    },
    changeMapJSON(url, id, changed) {
      var vm = this;
      clearFeatures();
      $.getJSON(url, (data) => {
        vm.wgTree = [];
        vm.wgTree.push({
          name: data.gridName,
          type: 'FeatureCollection',
          id: data.gridNo,
          cp: data.cp
        });
        currentGirdNo = data.gridNo;
        vm.currentSpaceName = data.gridName;
        currentSpaceId = getSpaceId(data.gridName);
        boundaryData = data;
        if (id) { // 指定默认打开某地
          vm.gotoSomeplaceByGridid(id);
          vm.showGridDetail();
        } else {
          // 加载区级地图
          vm.addFeatureV1();
          map.setCenterAndZoom($Config.CENTER, $Config.ZOOM, 10);
          vm.showGridDetail();
        }
      });
      changed && changed(window, map, vm);
    }
  },
  mounted: function () {
    map = new LwMap('div3d', $Config.CENTER, [$Config.ZOOM, ...($Config.ZOOMS || [3, 18])], 
      $.extend({ pitch: 35, rotation: -10, viewMode: '3D'}, $Config.AMAP_INIT_CONFIG || {})
    );
    var vm = this;
    map.loadPromise.then(() => {
      if ($Config.MAPJSON_URL != '0') {
        $.getJSON($Config.MAPJSON_URL || './mapJSON.json', (data) => {
          vm.wgTree.push({
            name: data.gridName,
            type: 'FeatureCollection',
            id: data.gridNo,
            cp: data.cp
          });
          currentGirdNo = data.gridNo;
          vm.currentSpaceName = data.gridName;
          currentSpaceId = getSpaceId(data.gridName);
          boundaryData = data;
          if (gridId || spaceName) { // 指定默认打开某地
            if (gridId) {
              vm.gotoSomeplaceByGridid(gridId);
            } else {
              vm.gotoSomeplaceByGridname(spaceName);
            }
            vm.showGridDetail();
          } else {
            // 加载区级地图
            vm.addFeatureV1();
            map.setCenterAndZoom($Config.CENTER, $Config.ZOOM, 10);
            vm.showGridDetail();
          }
          parent.mapLoaded && parent.mapLoaded(window, map, vm);
        });
      } else {
        parent.mapLoaded && parent.mapLoaded(window, map, vm);
      }
    });
  }
});